home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
tos.arc
/
keytbl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-09-03
|
2KB
|
127 lines
#include <stdlib.h>
#include <stdio.h>
#include <tos.h>
#define SUCCESS 0
#define FAILURE 1
void put(unsigned char * ptr, char * comment, char * name);
void putone(unsigned char ch);
char * comments[] =
{
"unshifted", "shifted", "capslocked"
};
char * names[] =
{
"keynorm", "keyshft", "keycaps"
};
FILE * fdes;
void main(int argc, char * argv[])
{
register i;
unsigned char ** tostbl;
char * def_tbl = (char *) -1L;
fdes = stdout;
if (--argc)
{
if ((fdes = fopen(*++argv, "w")) == (FILE *) 0)
{
fprintf(stderr, "can't open output file %s\n", *argv);
exit(FAILURE);
}
}
/*
* fetch pointer to table of 3 pointers to TOS tables
*/
tostbl = (unsigned char **) Keytbl(def_tbl, def_tbl, def_tbl);
/*
* sanity
*/
for (i = 0; i < 3; i++)
{
if (tostbl[i][1] != 033)
{
fprintf(stderr, "bad TOS table[%d]\n", i);
#ifdef USE_DESKTOP
getchar();
#endif
exit(1);
}
}
/* some lines comment */
fprintf(fdes,
"/* %s: contains the current key maps retrieved\n", *argv);
fprintf(fdes, " * from the TOS environment.\n");
fprintf(fdes, " * Use in the directory 'kernel'\n */\n\n");
/*
* copy each of the three tables into stdout or header file.
*/
for (i = 0; i < 3; i++)
put(tostbl[i], comments[i], names[i]);
exit(SUCCESS);
}
void put(unsigned char * ptr, char * comment, char * name)
{
int i;
int j;
fprintf(fdes, "/* Scan codes to ASCII for %s keys */\n", comment);
fprintf(fdes, "PUBLIC unsigned char %s[] = {\n", name);
for (i=0; i < 16; i++)
{
fprintf(fdes, "/*%02x*/ ", i*8);
for (j=0; j<8; j++)
putone(ptr[i*8+j]);
fprintf(fdes, "\n");
}
fprintf(fdes, "};\n\n");
}
void putone(unsigned char ch)
{
switch (ch)
{
case '\'':
fprintf(fdes, " '\\'',");
break;
case '\\':
fprintf(fdes, " '\\\\',");
break;
case '\b':
fprintf(fdes, " '\\b',");
break;
case '\r':
fprintf(fdes, " '\\r',");
break;
case '\t':
fprintf(fdes, " '\\t',");
break;
case 0x9c:
fprintf(fdes, " '@',");
break;
default:
if ((ch > 0x1f) && (ch < 0x7f))
fprintf(fdes, " '%c',", ch);
else
fprintf(fdes, " 0x%02X,", (unsigned char) ch);
}
}